package com.example.service.impl;

import com.example.dao.AdminDao;
import com.example.dao.impl.AdminDaoImpl;
import com.example.pojo.Admin;
import com.example.pojo.Announce;
import com.example.pojo.Help;
import com.example.pojo.User;
import com.example.service.AdminService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("adminService")
public class AdminServiceImpl implements AdminService {
    @Resource(name = "adminDao")
    public AdminDao adminDao;

    public Admin login(String username,String password) {
        return adminDao.login(username,password);
    }

    public Map<String,Object> getTopicData() {
        return adminDao.getTopicData();
    }

    public Map<String,Object> getTypeCount() {
        return adminDao.getTypeCount();
    }

    public List<Map<String,Object>> getUserList() {
        return adminDao.getUserList();
    }

    public Integer addUser(String username,String password,String nickname,String name,String sex,String avatar,
                           String phone,String idNumber,String enterYear,String className,String subject,String email) {
        if(adminDao.addUser(username, password, nickname, name, sex, avatar, phone, idNumber, enterYear, className,
                subject, email) == 1) {
            return 200;
        } else {
            return 500;
        }
    }

    public List<Map<String,Object>> getTopicList() {
        return adminDao.getTopicList();
    }

    public List<Announce> getAnnounceList() {
        return adminDao.getAnnounceList();
    }

    public List<Help> getHelpList() {
        return adminDao.getHelpList();
    }

    public Integer addAnnounce(Integer aId,String avatar,String title,String content) {
        int res = adminDao.insertAnnounce(aId,avatar,title,content);
        if(res == 1) {
            return 200;
        } else {
            return 500;
        }
    }

    public Integer addHelp(Integer aId,String avatar,String title,String content) {
        int res = adminDao.insertHelp(aId,avatar,title,content);
        if(res == 1) {
            return 200;
        } else {
            return 500;
        }
    }

    public Integer deleteTopic(Integer tId) {
        int res = adminDao.deleteTopic(tId);
        if(res == 1) {
            return 200;
        } else {
            return 500;
        }
    }

    public Integer checkTopic(Integer tId,String checkStatus) {
        int res = adminDao.checkTopic(tId,checkStatus);
        if(res == 1) {
            return 200;
        } else {
            return 500;
        }
    }

}
